<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<script th:inline="javascript">
  $(document).ready(function(){
      $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
      $('#transferContainer').transfer({
          titles: ['待选通道', '已选通道'],
          search: true,
          uniqueId: 'code', //唯一id
          type: 'post',
          maxSelect: 20,
          diffKey: 'flag',
          unselectColumns: [{
              field: 'flag',
              checkbox: true
          }, {
              field: 'name',
              title: '通道名称'
          },{
              field: 'weight',
              title: '通道权重'
          },{
              field: 'level',
              title: '通道优先级'
          },{
              field: 'code',
              title: '通道编码'
          }]
      });

      changeData();
      $("#service_type").change(function () {
          changeData();
      });
  });
  $(function(){
	  middlegroup.admin.menu[[${OP.menuId}]].save = function(obj) {

          //获取选中的值
          //var selectData = $('#transferContainer').transfer('getData', 'selectData');
          var selectCode = '';

          var arr = [];
          $("#transferSelectTable").find('tbody tr').each(function() {
              selectCode +=$(this).find('td').eq(4).text()+"|"+$(this).find('td').eq(2).text()+"|"+$(this).find('td').eq(3).text()+",";
          });
          selectCode=(selectCode.substring(selectCode.length-1)==',')?selectCode.substring(0,selectCode.length-1):selectCode;

          $('#selectCode').attr("value", selectCode);

          var unselectCode = '';
          var unselectData = $('#transferContainer').transfer('getData', 'unselectData');
          Object.keys(unselectData).forEach(function (key) {
              unselectCode += unselectData[key].code + ",";
          });

          unselectCode=(unselectCode.substring(unselectCode.length-1)==',')?unselectCode.substring(0,unselectCode.length-1):unselectCode;
          $('#unselectCode').attr("value", unselectCode);
		var $form = $("#menu[[${OP.menuId}]]Form");
  		if($form.valid()){
  			middlegroup.ajaxJson({url:"/op_save_[[${OP.menuId}]]",data:$form.serializeArray()},function(){
  				middlegroup.closeWindow();
				$('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('refresh');
    		});
  		}; 
	};	 
  });
  function changeData() {
      var serviceType = $("#service_type").val();
      var subjectCode = $("#subject_code").val();
      var code = $('#code').val();
      $.ajax({
          url: [[${MENU.channel}]] + '/getSubjectChannels' + "?serviceType=" + serviceType + "&subjectCode=" + subjectCode+"&code="+code,
          success: function (json) {
              $('#transferContainer').transfer('refresh', json);
              $('#transferSelectTable,#transferUnselectTable').find('tbody tr').each(function() {
                  var a = $(this).find('td').eq(2);
                  a.attr("contenteditable", "true");
                  var b = $(this).find('td').eq(3);
                  console.log(b);
                  b.attr("contenteditable", "true");
              });
          }
      });

  }
</script>
<div class="ibox float-e-margins animated fadeInRight">
	<div class="ibox-content">
		<form class="form-horizontal m-t required-validate" th:id="@{menu{menuId}Form(menuId=${OP.menuId})}" method="POST" >
			<input type="hidden" name="id" th:value="${dto?.id}" />
			<input type="hidden" name="unselectBankCode" id="unselect_bank_code">
			<input type="hidden" name="subjectCode" id="subject_code" th:value="${dto?.subjectCode}">
			<input type="hidden" name="selectCode" id="selectCode">
			<input type="hidden" name="unselectCode" id="unselectCode">
			<div class="form-group">
				<label class="col-sm-3 control-label">商户名称：</label>
				<div class="col-sm-8">
					<input name="name" class="form-control" type="text"
						th:value="${dto?.name}" validate="{required:true,messages:{required:'请填写商户名称'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户编码：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="code" id="code" th:readonly="${null != dto?.id}" th:value="${dto?.code}"
						validate="{required:true,messages:{required:'请填写商户编码'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属主体：</label>
				<div class="col-sm-8">
					<select class="selectpicker form-control" name="subjectCode" data-live-search="true" th:disabled="${null != dto?.id}">
						<option value="0">请选择主体</option><p ></p>
						<option th:each="subject : ${subjectList}" th:value="${subject.code}" th:selected="${subject.code == dto?.subjectCode} ? 'selected'" th:text="${subject.name}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户负责人手机号：</label>
				<div class="col-sm-8">
					<input name="phone" class="form-control" id="phone"  th:value="${dto?.phone}"
						   validate="{required:true,messages:{required:'请填写商户负责人手机号'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户负责人邮箱：</label>
				<div class="col-sm-8">
					<input name="email" class="form-control" id="email"  th:value="${dto?.email}"
						   validate="{required:true,messages:{required:'请填写商户负责人邮箱'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户网关地址(回调通知等使用)：</label>
				<div class="col-sm-8">
					<input name="serviceUrl" class="form-control" id="serviceUrl"  th:value="${dto?.serviceUrl}"
						   validate="{required:true,messages:{required:'请填写商户网关地址'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户RSA公钥：</label>
				<div class="col-sm-8">
					<input name="rsaPubKey" class="form-control" id="rsaPubKey"  th:value="${dto?.rsaPubKey}"
						   validate="{required:true,messages:{required:'请填写商户RSA公钥'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户RSA私钥：</label>
				<div class="col-sm-8">
					<input name="rsaPriKey" class="form-control" id="rsaPriKey"  th:value="${dto?.rsaPriKey}"
						   validate="{required:false,messages:{required:'请填写商户RSA私钥'}}"/>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">通道类型：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" name="serviceType" id="service_type">
						<option value="OUT" selected="selected">出款</option>
						<option value="IN">收款</option>
					</select>
				</div>
				<label class="col-sm-3 control-label">商户通道绑定：</label>
				<div class="col-sm-8">
					<div id="transferContainer" class="row" style="height: 600px;width: 100%;"></div>
				</div>
			</div>
		</form>
	</div>
</div>
</html>